package com.example.primarycalculator2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.ashokvarma.bottomnavigation.ShapeBadgeItem;
import com.ashokvarma.bottomnavigation.TextBadgeItem;

public class UserActivity extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener{
    BottomNavigationBar bottomNavigationBar;
    @Nullable
    TextBadgeItem numberBadgeItem;
    @Nullable
    ShapeBadgeItem shapeBadgeItem;
    int lastSelectedPosition = 2;

    TextView textView;

    public static final String TAG="UserActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate: ");
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);

        textView=findViewById(R.id.right_rate);
        SharedPreferences sharedPreferences=getSharedPreferences("menta", Activity.MODE_PRIVATE);
        float num=Float.valueOf(sharedPreferences.getInt("num",1));
        float numerror=Float.valueOf(sharedPreferences.getInt("numerror",0));
        textView.setText(""+(num-numerror)/num);


        bottomNavigationBar = findViewById(R.id.bottom_navigation_bar_user);
        bottomNavigationBar.setTabSelectedListener(this);
        refresh();

    }

    @SuppressLint("WrongConstant")
    private void refresh() {

        bottomNavigationBar.clearAll();
        numberBadgeItem = new TextBadgeItem()
                .setBorderWidth(4)
                .setBackgroundColorResource(R.color.blue)
                .setText("" + lastSelectedPosition)
                .setHideOnSelect(false);
        shapeBadgeItem = new ShapeBadgeItem()
                .setShape(5)
                .setShapeColorResource(R.color.teal)
                .setGravity(Gravity.TOP | Gravity.END)
                .setHideOnSelect(false);
        numberBadgeItem.toggle();
        shapeBadgeItem.toggle();
        bottomNavigationBar.setMode(2);
        bottomNavigationBar
                .addItem(new BottomNavigationItem(R.drawable.ic_home_white_24dp, "home").setActiveColorResource(R.color.orange).setBadgeItem(numberBadgeItem))
                .addItem(new BottomNavigationItem(R.drawable.ic_book_white_24dp, "error book").setActiveColorResource(R.color.teal))
                .addItem(new BottomNavigationItem(R.drawable.ic_github_circle_white_24dp, "user").setActiveColorResource(R.color.blue).setBadgeItem(shapeBadgeItem))
                .setFirstSelectedPosition(lastSelectedPosition > 2 ? 2 : lastSelectedPosition)
                .initialise();
    }



    @Override
    public void onTabSelected(int position) {
        lastSelectedPosition = position;
        Log.d(TAG, "onTabSelected: "+lastSelectedPosition);
        switch (lastSelectedPosition){
            case 0:
                Intent intent=new Intent(UserActivity.this,MainActivity.class);
                startActivity(intent);
                break;
            case 1:
                Intent intent1=new Intent(UserActivity.this,ErrorActivity.class);
                startActivity(intent1);
                break;
            case 2:
                break;
        }

    }

    @Override
    public void onTabUnselected(int position) {

    }

    @Override
    public void onTabReselected(int position) {

    }


}